iT邦幫忙

2022 iThome 鐵人賽

DAY 24
0
Modern Web

clojure 刷刷鍋系列 第 24

Clojure 肉片 -第 24 塊

  • 分享至 

  • xImage
  •  

【今日湯底】

Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.

If you want to know more: http://en.wikipedia.org/wiki/DNA

In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G". Your function receives one side of the DNA (string, except for Haskell); you need to return the other complementary side. DNA strand is never empty or there is no DNA at all (again, except for Haskell).

More similar exercise are found here: http://rosalind.info/problems/list-view/ (source)

Example: (input --> output)

"ATTGC" --> "TAACG"
"GTAT" --> "CATA"

(必須通過以下測試)

(ns complementary-dna-tests
  (:require
    [clojure.test :refer :all]
    [complementary-dna :refer [dna-strand]]))

(deftest sample-tests
  (is (= (dna-strand "ATCG") "TAGC")))

【我的答案】

(ns complementary-dna)

(defn dna-strand [dna]
  (clojure.string/replace dna #"A|T|C|G" {"A" "T" "T" "A" "C" "G" "G" "C"})
)

【其他人的答案】

(ns complementary-dna)

(defn dna-strand [dna]
    (apply str (map {\A \T \C \G \G \C \T \A} dna)))
(ns complementary-dna)

(require '[clojure.string :refer [replace]])

(defn dna-strand [dna]
  (replace dna #"\S" {"A" "T" "C" "G" "T" "A" "G" "C"}))

上一篇
Clojure 肉片 -第 23 塊
下一篇
Clojure 肉片 -第 25 塊
系列文
clojure 刷刷鍋30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言